﻿<%@ Page Title="" Language="C#" MasterPageFile="~/EditWidows/eYUITreeList.Master"
    AutoEventWireup="true" CodeBehind="EYUITreeList.aspx.cs" Inherits="ZX.WebApp.EditWidows.EYUITreeList" %>

<%@ Register Assembly="ZX.Web.UI.Controls" Namespace="ZX.Web.UI.Controls" TagPrefix="cc1" %>
<asp:Content ContentPlaceHolderID="headerPlace" runat="server">
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/calendar/assets/skins/sam/calendar.css" />

    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/reset-fonts-grids/reset-fonts-grids.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/menu/assets/skins/sam/menu.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/button/assets/skins/sam/button.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/resize/assets/skins/sam/resize.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/layout/assets/skins/sam/layout.css" />
    <link rel="stylesheet" type="text/css" href="../Scripts/yui_2.9.0/build/datatable/assets/skins/sam/datatable.css" />
    <link rel="stylesheet" type="text/css" href="../Scripts/yui_2.9.0/build/paginator/assets/skins/sam/paginator.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/treeview/assets/skins/sam/treeview.css" />

    <!--begin custom header content for this example-->

    <!--end custom header content for this example-->
    <!-- Dependencies -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/element/element-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/datasource/datasource-min.js"></script>
    <!-- OPTIONAL: JSON Utility (for DataSource) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <!-- OPTIONAL: Connection Manager (enables XHR for DataSource) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <!-- OPTIONAL: Get Utility (enables dynamic script nodes for DataSource) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/get/get-min.js"></script>
    <!-- OPTIONAL: Drag Drop (enables resizeable or reorderable columns) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/dragdrop/dragdrop-min.js"></script>
    <!-- OPTIONAL: Calendar (enables calendar editors) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/calendar/calendar-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/datatable/datatable-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/layout/layout-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/button/button-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/container/container-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/treeview/treeview-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/resize/resize-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/paginator/paginator-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/event-delegate/event-delegate-min.js"></script>
    <script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="../Scripts/Public.js" type="text/javascript"></script>
    <script src="../Scripts/fullscreen.js" type="text/javascript"></script>
    <script src="../Scripts/Jquery.form.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="HeaderControl" runat="server">

    <%= BtnItems %>
    <button type="button" id="btnFull" name="btnFull">
        全屏</button>
    <button type="button" id="btnModuleHelp" name="btnModuleHelp">
        帮助</button>
    <button type="button" id="btnReload" name="btnReload">
        刷新</button>
    <button type="button" id="btnClose" name="btnClose">
        关闭当前页</button>
         
    <script type="text/javascript">

        YAHOO.example.init = function () {
        // "click" event handler for each Button instance
        function onButtonClick(p_oEvent) {
                 YAHOO.log("You clicked button: " + this.get("id"), "info", "example1");
                 switch(this.get("id"))
                 {
                     <% =InitBtnEvents %>
                    case "btnFull": 
                         fnFull();
                         break;
                    case "btnModuleHelp":
                         fnModuleHelp();
                         break;
                    case "btnClose":
                         window.parent.$("#tabs").tabs('close','<% =PageTitle %>');
                         break;
                    case "btnReload":
                         fnReload();
                         break;
                    case "btnCheck":
                         fnCheck();
                         break;
                    default:
                         break;
                 }                        
        }


        YAHOO.util.Event.onContentReady("toolbar", function () {
        <% =BtnEvents  %>
        var btnFull = new YAHOO.widget.Button("btnFull");
        btnFull.on("click", onButtonClick);
        var btnModuleHelp = new YAHOO.widget.Button("btnModuleHelp");
        btnModuleHelp.on("click", onButtonClick);
        var btnClose = new YAHOO.widget.Button("btnClose");
        btnClose.on("click", onButtonClick);
        var btnReload = new YAHOO.widget.Button("btnReload");
        btnReload.on("click", onButtonClick);
        
        var btnCheck=new YAHOO.widget.Button("btnCheck");
        btnCheck.on("click", onButtonClick);
//        var btnQuickQuery= new YAHOO.widget.Button("btnQuickQuery");
//        btnQuickQuery.on("click", onButtonClick);
        });
    }();

    function AddButton() {
        var button = document.createElement('button');
        button.innerHTML = 'add tab';
        YAHOO.util.Event.on(button, 'click', addTab);
        tabView.appendChild(button);
    }
    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="leftPlaceHoder" runat="server">
<%--    搜索:<input type="text" id="txtdeptName" onkeyup="serachDept();" style="width: 100px" />
    <button id="btnexpend">
        扩展</button>--%>
    <cc1:TreeView ID="treeDiv1" runat="server" TableName='SysFunction' Caption='Name'
        Key='FunctionID' ParentKey='ParentID' path='FunctionPath'></cc1:TreeView>
    <script type="text/javascript">
        var serachDept = function () {
            var key = $("#txtdeptName").val();
            $("a").css("color", "")
            $("a:contains('" + key + "')").css("color", "red");
        }
        //设置扩展与收缩
        $("#btnexpend").toggle(function () {
            $("#btnexpend").html("收缩");
            tree1._nodes[1].expandAll();
        }, function () {
            $("#btnexpend").html("扩展");
            tree1._nodes[1].collapseAll();
        });

      
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="DataPlaceHolder" runat="server">


    <div id="search" style="display: none">
        <select id="drpSearch">
            <option selected="selected" value="CustomerName">客户名称</option>
            <option value="Code">客户编码</option>
        </select>
        <input type="text" id="txtSearch" name="txtSearch" />
        <input type="button" id="btnSearch" name="btnSearch" value="查找" style="width: 50px;
            text-align: center;" />
    </div>
    <div id="json">
    </div>
    <div id="bottom">
        <div id="pagetotal" style="float: left; height: 25px; padding: 8px; margin-top: 3px;
            width: 100px;">
        </div>
        <div id="page" style="float: left">
        </div>
    </div>
    <form id="form2" action="../Extend/AjaxData/DataSave.aspx">
    <textarea style="display: none" id="jsonDataContent" rows="2" cols="2" name="jsonDataContent"></textarea>
    <textarea style="display: none" id="jsonDetails" rows="2" cols="2" name="Details"></textarea>
    </form>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ScriptPlaceHolder" runat="server">

<script src="../Scripts/appjs/model.<% =EntityName %>.js" type="text/javascript"  language="javascript"></script>
    <script type="text/javascript">
    var PageTotal;
    var pageindex = 1;
    var pagesize = 25;
        var const_entityName="<%=EntityName%>",
        const_isGetDeptInfo ="<%=IsGetDeptInfo %>" //是否需要取得部门
        fkey="<%=Guid.Empty%>",
        const_functionId   ="<% =FunctionID %>",//自定义条件
        const_Order ="<% =Order %>",           //排序  
        const_UserId = "<% = UserId %>",       //
        const_DataFields = [<% =DataFields %>],
        const_DataColums = [<% =DataColums %>],
        const_EditEntity = "<% =EditEntity %>",//编辑实体名
        const_EditWindowWidth = "<% =EditWindowWidth %>px",
		const_EditWindowHeight = "<% =EditWindowHeight %>px",
        const_CustomCondition = encodeURI("<% =DefineCondition %>"),//查询方案条件
        const_Condition =  encodeURI("<% =Condition %>"),
        const_PageTitle=encodeURI("<% =PageTitle %>"),
        initialRequestUrl="entity=<%=EntityName%>&order=<% =Order %>&zip=94089&results=10&output=json&r="+Math.random()+"&condition="+window.decodeURI("<%=ForeignKey%>='"+fkey+"'");
        const_entityID = "<% =EntityId %>",  //实体ID名称
        _NoEntity = getPar1("NoEntity") == "yes" ? "DataTable" : "";
    </script>
    <script type="text/javascript" src="../Scripts/yui.list.YUITreeList1.js"></script>
    <script type="text/javascript">
        //改变节点处理函数
        var _Caption;
        var _key;
       
        function Native(caption, key) {
            //debugger;
            fkey = key;
            _key = key;
            _Caption = caption;
            const_CustomCondition = "";
            //if (const_entityName == "V_hrEmployee" || const_entityName == "V_hrEmployeeLiZhi" || const_entityName == "V_hrEmployeeLiTuiXiu" || const_entityName == "V_hrEmployeeFeiZhengShi" || const_entityName == "V_wkWorkResult" || const_entityName == "V_wkEmpMonthWorkResult" || const_entityName == "V_wkProjectWorkResult") {
            if(const_isGetDeptInfo=="True"){
                GetDeptInfo(key);
            }
            else{
                const_Condition = window.encodeURI("<%=ForeignKey%> ='" + fkey + "'");
                if (getPar1("condition") != "") {
                    const_Condition = const_Condition + " and " + getPar1("condition");
                }
                initialRequestUrl = "pageindex=1&entity=<%=EntityName%>&order=<% =Order %>&zip=94089&results=10&output=json&r=" + Math.random() + "&condition=" + window.encodeURI("<%=ForeignKey%>='" + fkey + "'");
                BindData();
                GetTotal("../Extend/AjaxData/" + _NoEntity + "JSONList.aspx?onlyTotal=true&" + initialRequestUrl);
            }
            setTreeNodeState(fkey);
            currentNode.refresh();
            if (currentNode.expanded) {
                currentNode.collapse();
            }
            else {
                currentNode.expand();
            }
        }

        function GetDeptInfo(key) {
        //ebugger
            var _url = "../Extend/AjaxData/" + _NoEntity + "JSONList.aspx?pageindex=1&entity=DatDepartment&condition=" + window.encodeURI("DeptID='" + key + "'");
            YAHOO.util.Connect.asyncRequest('POST', _url, {
                success: function (res) {
                    //debugger;
                    var o = eval("[" + res.responseText + "]")[0];
                    var deptPath = o.rows[0].DeptPath;
                    const_Condition = window.encodeURI("DeptPath like '" + deptPath + "%' ")
                    if (getPar1("condition") != "") {
                        const_Condition = const_Condition + " and "+ getPar1("condition");
                    }
                    //const_CustomCondition = window.encodeURI("DeptPath like '" + deptPath + "%'");
                    initialRequestUrl = "pageindex=1&entity=<%=EntityName%>&order=<% =Order %>&zip=94089&results=10&output=json&r=" + Math.random() + "&condition=" + const_Condition + "&customCondition=" + const_CustomCondition;
                    BindData();
                    var __url = "../Extend/AjaxData/" + _NoEntity + "JSONList.aspx?onlyTotal=true&" + initialRequestUrl;
                    GetTotal(__url);
                },
                failure: function (error) {

                }
            }, null);
        }

        //标记树节点状态
        function setTreeNodeState(id) {
            //标识选中节点
            var childNodes = tree1.getNodeCount();
            var topNodes = tree1.getNodesByProperty("href");
            for (var i = 0; i < childNodes; ++i) {
                //var id = .href.split("#@")[1];
                if (topNodes[i].html.indexOf(id) > -1) {
                    //for (var node in topNodes) {
                    //topNodes[i].highlightState = 1; // setNodesByProperty('highlightState');
                    currentNode = topNodes[i];
                    break;
                }
            }
        }


      (function () {
         var Dom = YAHOO.util.Dom,
            Event = YAHOO.util.Event;
         Event.onDOMReady(function () {
             var layout = new YAHOO.widget.Layout({
                 minWidth: 1000,
                 minHeight: 500,
                 units: [
                    { position: 'left', width: 200, header: " ", resize: true, body: 'left', gutter: '1px 1px', collapseSize: 50, scroll: true, maxWidth: 300 },
                    { position: 'center', minWidth: 400, minHeight: 200 }
                ]
             });
             layout.on('render', function () {
                 var el = layout.getUnitByPosition('center').get('wrap');
                 var layout2 = new YAHOO.widget.Layout(el, {
                     parent: layout,
                     minWidth: 400,
                     minHeight: 200,
                     units: [
                        { position: 'top', body: 'toolbar', height: 35, gutter: '1px', maxHeight: 80 },
                        { position: 'bottom', height: 35, resize: true, body: 'bottom', gutter: '1px', maxHeight: 130 },
                        { position: 'center', body: 'data', gutter: '1px', scroll: true }
                    ]
                 });
                 layout2.render();
             });
             layout.render();
             InitLeftData();
         });

         function InitLeftData() {
             tree1 = new YAHOO.widget.TreeView("treeDiv1");
             tree1.setNodesProperty('propagateHighlightUp', true);
             tree1.setNodesProperty('propagateHighlightDown', true);
             tree1.subscribe('clickEvent', tree1.onEventToggleHighlight);
             tree1.render();
             tree1._nodes[1].expand();
             BindData();
         }

     })();
     var _fn, _ids;
     var GetSelected = function (ids) {
         _ids = ids;
     }

     function RefreshTreeData(caption, key) {
         //debugger;
         var modeText = "<a href='#" + key + "' style='display:block;cursor:hand' onclick=\"Native('" + caption + "','" + key + "')\">" + caption + "</a>";
         //添加一个节点到组织架构树上
         addNode(modeText);         
     }

     var currentNode = null;
     //标记树节点状态
     function setTreeNodeState(id) {
         //标识选中节点
         var childNodes = tree1.getNodeCount();
         var topNodes = tree1.getNodesByProperty("href");
         for (var i = 0; i < childNodes; ++i) {
             //var id = .href.split("#@")[1];
             if (topNodes[i].html.indexOf(id) > -1) {
                 currentNode = topNodes[i];
                 currentNode.labelStyle = "icon-doc";
                 break;
             }
         }
     }

     //添加节点
     function addNode(sLabel, id) {
         //debugger
         setTreeNodeState(fkey);
         var oChildNode = new YAHOO.widget.HTMLNode(sLabel, currentNode, false);
         if (currentNode != null) {
             currentNode.refresh();
             currentNode.expand();
         }
     }

     //删除节点
     function deleteNode() {
         setTreeNodeState(fkey);
         tree1.removeNode(currentNode);
         tree1.draw();
     }


     var _need = 0;
     $(document).ready(function () {
         //
         if ((const_entityName == "V_salBaseSalary" || const_entityName == "V_salEmployeeSalaryResult") && _need == 0) {
             _fullScreen();
             _need = 1;
         }
     })

     //密码验证
     function fnCheck() {
         $("#btnCheck").attr("disabled", true);
         var pwd = $("#tPassword").val();
         YAHOO.util.Connect.asyncRequest('POST', "../EHR/hrSalaryAjax.aspx?flag=checkpwd&userPwd=" + pwd+"&r="+Math.random(), {
             success: function (res) {
                 try {
                     var str = res.responseText;
                     if (str == "0") {
                         $("#tPassword").val("");
                         _unfullScreen();
                     }
                     else {
                         alert("密码错误!");
                     }
                     $("#btnCheck").attr("disabled", false);
                 }
                 catch (e) {
                 }
                 finally {
                 }
             },
             failure: function (error) {
                 alert("数据错误：" + error.statusText);
             }
         }, null);
     }
    </script>
     <!-- 定义数据格式化方法 -->
    <script src="../Scripts/yui.list.dataformat.js" type="text/javascript"></script>
    <!--  用于加载自定义脚本 -->
   
    <script src="../Scripts/yui.list.YUITreeList.button.event.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        var Save = function () {
            //debugger;
            var list = mDataTable.getRecordSet()._records;
            var elist = [];
            for (var i = 0; i < list.length; i++) {
                elist.push(list[i]._oData);
            }

            url = "../Extend/AjaxData/DataSave.aspx";
            var jsonStr = YAHOO.lang.JSON.stringify(elist);
            var TextCtrl = document.getElementById("jsonDataContent");
            TextCtrl.value = jsonStr;
            var formObject = document.getElementById('form2');
            YAHOO.util.Connect.setForm(formObject);
            var SaveUrl = url + "?r=" + Math.random() + "&flag=1&action=setTimeResult&functionid=" + const_functionId + "&entity=" + const_entityName; //+"&json=" + encodeURI(jsonStr.replace(/&/g,"[A]").replace(/'/g,"''"));
            YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
                success: function (res) {
                    try {
                        var str = res.responseText;
                        if (str == "1") {
                            alert("数据保存成功");
                            //parent.closeWin();
                        }
                        else {
                            alert(str + "\n" + "数据保存失败!");
                        }
                    }
                    catch (e) {
                    }
                    finally {
                    }
                },
                failure: function (error) {
                    alert("数据错误：" + error.statusText);
                }
            }, null);
        }

    YAHOO.util.Event.addListener(document, 'keydown', function (ev) {
        if (ev.ctrlKey && ev.keyCode == "72") {
            fnModuleHelp();
            //alert("帮助");
        }
        if (ev.ctrlKey && ev.keyCode == "83") {

            fnListSetting();
            //alert("设置");
        }

        if (ev.ctrlKey && ev.keyCode == "85") {
            _fullScreen();
        }
    });
</script>
</asp:Content>
